'use strict';

const validator = require('validator')
const util = require('util')

module.exports = {
    isNumber: {
        message: 'SHOULD_NUMBER',
        exec: util.isNumber
    },

    isObject: {
        message: 'SHOULD_STRING',
        exec: util.isObject
    },

    isArray: {
        message: 'SHOULD_ARRAY',
        exec: util.isArray
    },

    isString: {
        message: 'SHOULD_STRING',
        exec: util.isString
    },

    isPhone: {
        message: 'PHONE_ERROR',
        exec(val) {
            if (!util.isString(val)) return false
            return validator.isMobilePhone(val, 'zh-CN')
        }
    },

    isEmail: {
        message: 'EMAIL_ERROR',
        exec(val) {
            if (!util.isString(val)) return false
            return validator.isEmail()
        }
    },

    isPassword: {
        message: 'PASSWORD_ERROR',
        exec(val) {
            if (!util.isString(val)) return false
            return /.{6,64}/.test(val)
        }
    },

    isVerifyCode: {
        message: 'VERIFY_CODE_ERROR',
        exec(val) {
            if (!util.isString(val)) return false
            return /[0-9]{6}/.test(val)
        }
    }
}